package edu.rakovic.elearning.beans;

import java.util.Random;

import edu.rakovic.elearning.interfaces.Course;
import edu.rakovic.elearning.interfaces.Exam;
import edu.rakovic.elearning.interfaces.User;

public class ExamBean implements Exam {
	
	private String id;
	private Course course;
	private User user;
	//other side connection should be implemented as well !
	// - lists for course and user
	
	private int grade;
	private boolean passed;
	
	public Exam executeExamCreation(User user, Course course, int mark){
		course.getExamList().add(this);
		user.getTakenExams().add(this);
		
		this.setGrade(mark);
		if(this.grade<6){
			this.setPassed(false);
		}else
			this.setPassed(true);
		
		this.setCourse(course);
		this.setUser(user);
		return this;
		
	}
	
	//generates random mark/grade
	public int generateRandomMark(){
		Random rInt = new Random();
		int mark  = rInt.nextInt(10);
		if(mark==1) return 5;
		if(mark == 5) return 5;
		if(mark<6) mark +=5;
		return mark;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getId() {
		return id;
	}
	public Course getCourse() {
		return course;
	}
	public void setCourse(Course course) {
		this.course = course;
	}
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	public int getGrade() {
		return grade;
	}
	public void setGrade(int grade) {
		this.grade = grade;
	}
	public boolean isPassed() {
		return passed;
	}
	public void setPassed(boolean passed) {
		this.passed = passed;
	}

	

}
